/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ywk.openFeignServer2.consumer;

import com.ywk.openFeignApi.User;
import feign.Headers;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient("openFeign-server1") // 指向服务提供者应用
public interface EchoService {

    @GetMapping("/echo/{message}")
    @Headers({"Content-Type: application/json;charset=UTF-8"})//添加header有四种方式
    String echo(@PathVariable("message") String message);

    @GetMapping(value = "/select")
    User select(@RequestParam(value = "id") Integer id, @RequestParam(value = "name") String name);

    /**
     * springboot版本在2.1之后，GetMapping传递对象时要用@SpringQueryMap，之前用@RequestParam
     * @SpringQueryMap的作用：将对象参数拼接到请求路径里（所以提供消费的接口参数不能用@RequestBody修饰），但是无法解析父类的属性，会导致类型不一致报错
     * 解决参考：https://blog.csdn.net/qq_47493459/article/details/124290580
     * @param user
     * @return
     */
    @GetMapping(value = "/selectList")
    List<User> selectList(@SpringQueryMap User user);

    @RequestMapping(value = "/getStr", method = RequestMethod.POST)
    String getStr(@RequestParam(value = "str") String str);

    @PostMapping(value = "/create", consumes = "application/json")
    @Headers({"Content-Type: application/json;charset=UTF-8"})//添加header有四种方式
    User create(@RequestBody User user);
}
